package com.smartbus.bus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smartbus.common.annotation.Log;
import com.smartbus.common.core.controller.BaseController;
import com.smartbus.common.core.domain.AjaxResult;
import com.smartbus.common.enums.BusinessType;
import com.smartbus.bus.domain.SystemSettings;
import com.smartbus.bus.service.ISystemSettingsService;
import com.smartbus.common.utils.poi.ExcelUtil;
import com.smartbus.common.core.page.TableDataInfo;

/**
 * 系统配置参数，存储各种可配置的系统参数和业务规则Controller
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/bus/settings")
public class SystemSettingsController extends BaseController
{
    @Autowired
    private ISystemSettingsService systemSettingsService;

    /**
     * 查询系统配置参数，存储各种可配置的系统参数和业务规则列表
     */
    @PreAuthorize("@ss.hasPermi('bus:settings:list')")
    @GetMapping("/list")
    public TableDataInfo list(SystemSettings systemSettings)
    {
        startPage();
        List<SystemSettings> list = systemSettingsService.selectSystemSettingsList(systemSettings);
        return getDataTable(list);
    }

    /**
     * 导出系统配置参数，存储各种可配置的系统参数和业务规则列表
     */
    @PreAuthorize("@ss.hasPermi('bus:settings:export')")
    @Log(title = "系统配置参数，存储各种可配置的系统参数和业务规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SystemSettings systemSettings)
    {
        List<SystemSettings> list = systemSettingsService.selectSystemSettingsList(systemSettings);
        ExcelUtil<SystemSettings> util = new ExcelUtil<SystemSettings>(SystemSettings.class);
        util.exportExcel(response, list, "系统配置参数，存储各种可配置的系统参数和业务规则数据");
    }

    /**
     * 获取系统配置参数，存储各种可配置的系统参数和业务规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('bus:settings:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(systemSettingsService.selectSystemSettingsById(id));
    }

    /**
     * 新增系统配置参数，存储各种可配置的系统参数和业务规则
     */
    @PreAuthorize("@ss.hasPermi('bus:settings:add')")
    @Log(title = "系统配置参数，存储各种可配置的系统参数和业务规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SystemSettings systemSettings)
    {
        return toAjax(systemSettingsService.insertSystemSettings(systemSettings));
    }

    /**
     * 修改系统配置参数，存储各种可配置的系统参数和业务规则
     */
    @PreAuthorize("@ss.hasPermi('bus:settings:edit')")
    @Log(title = "系统配置参数，存储各种可配置的系统参数和业务规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SystemSettings systemSettings)
    {
        return toAjax(systemSettingsService.updateSystemSettings(systemSettings));
    }

    /**
     * 删除系统配置参数，存储各种可配置的系统参数和业务规则
     */
    @PreAuthorize("@ss.hasPermi('bus:settings:remove')")
    @Log(title = "系统配置参数，存储各种可配置的系统参数和业务规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(systemSettingsService.deleteSystemSettingsByIds(ids));
    }
}
